<template>
  <el-dialog
    :title="title"
    :visible="visible"
    :top="top"
    :width="width + 'px'"
    :before-close="onClose"
  >
    <slot name="content-header" />
    <div class="container" :style="{ height: height + 'px' }">
      <div :style="{ 'opacity': dataLoading ? '1' : '0'}">
        数据加载中...
      </div>
      <div :style="{ 'opacity': !dataLoading ? '1' : '0'}">
        <slot name="content" />
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button v-if="!dataLoading" type="primary" :loading="loading" :disabled="loading" @click="onConfirm()">确定</el-button>
      <el-button type="danger" @click="onClose()">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: '默认标题'
    },
    type: {
      type: String,
      default: 'add'
    },
    visible: {
      type: Boolean,
      default: false
    },
    top: {
      type: String,
      default: '15vh'
    },
    width: {
      type: Number,
      default: 600
    },
    height: {
      type: Number,
      default: 300
    },
    loading: {
      type: Boolean,
      default: false
    },
    dataLoading: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    onClose() {
      this.$emit('onClose')
    },
    onConfirm() {
      this.$emit('onConfirm')
    }
  }
}
</script>

<style lang="scss" scoped>
.container{
  overflow-x: hidden;
  overflow-y: auto;
}
.el-dialog__wrapper {
  ::v-deep .el-dialog {
    border-top-left-radius: 7px;
    border-top-right-radius: 7px;
    .el-dialog__header {
      border-top-left-radius: 7px;
      border-top-right-radius: 7px;
      background-color: #1890ff;
      padding: 14px;
      .el-dialog__title {
        color: #fff;
        font-size: 16px;
        font-weight: 600;
      }
      .el-dialog__close {
        color: #fff;
      }
    }
    .el-dialog__body {
      padding: 14px;
      .el-input-number--default {
        width: 185px;
      }
      .el-input-number--medium {
        width: 184px;
      }
      .el-input-number--small {
        width: 184px;
      }
      .el-input-number--mini {
        width: 163px;
      }
      .el-select--default {
        width: 185px;
      }
      .el-select--medium {
        width: 184px;
      }
      .el-select--small {
        width: 184px;
      }
      .el-select--mini {
        width: 163px;
      }
      .el-radio {
        margin-right: 15px;
      }
      .el-radio:last-child {
        margin-right: 0;
      }
    }
    .el-dialog__footer {
      border-top: 1px solid #e8eaec !important;
      padding: 14px;
    }
  }
}
</style>
